<template>
  <div class="demo">
    <div class="item">
      <p>普通上传</p>
      <el-upload
        class="avatar-uploader"
        action="https://jsonplaceholder.typicode.com/posts/"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <i v-else class="el-icon-picture avatar-uploader-icon"></i>
        <span class="avatar-uploader-record" size="small">选择文件</span>
      </el-upload>
    </div>
    <div class="item">
      <p>多图上传 multiple</p>
      <el-upload
        class="avatar-uploader"
        action="https://jsonplaceholder.typicode.com/posts/"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
      >
        <img v-if="imageUrl" :src="imageUrl" class="avatar" />
        <i v-else class="el-icon-picture avatar-uploader-icon"></i>
        <span class="avatar-uploader-record">选择文件</span>
      </el-upload>
    </div>
    <div class="item">
      <p>文件上传 file</p>
      <el-upload
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-change="handleChange"
        :file-list="fileList"
      >
        <el-button size="small" type="success" style="font-size: 14px"
          >文件上传</el-button
        >
      </el-upload>
    </div>
    <div class="item">
      <p>自定义内容</p>
      <el-upload
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-change="handleChange"
        :file-list="fileList"
      >
        <el-button size="small" style="font-size: 14px">上传</el-button>
      </el-upload>
    </div>
    <div class="item">
      <p>自定义大小</p>
      <el-upload
        class="avatar-uploader"
        action="https://jsonplaceholder.typicode.com/posts/"
        :show-file-list="false"
        :on-success="handleAvatarSuccess"
        :before-upload="beforeAvatarUpload"
        style="width: 200px; height: 120px"
      >
        <img
          v-if="imageUrl"
          :src="imageUrl"
          class="avatar"
          style="width: 200px; height: 120px"
        />
        <i
          v-else
          class="el-icon-picture avatar-uploader-icon"
          style="width: 200px; height: 120px"
        ></i>
        <span class="avatar-uploader-record" style="left: 36%">选择文件</span>
      </el-upload>
    </div>
    <div class="item">
      <p>文件空间</p>
      <el-upload
        class="upload-demo"
        action="https://jsonplaceholder.typicode.com/posts/"
        :on-change="handleChange"
        :file-list="fileList"
      >
        <el-button size="small" style="font-size: 14px">点击上传</el-button>
      </el-upload>
    </div>
  </div>
</template>

<script></script>

<style lang="scss">
.demo {
  width: 100%;
  background-color: #fff;

  .item {
    padding: 10px;
    margin-bottom: 10px;

    p {
      margin-bottom: 10px;
      font-size: 14px;
    }
  }
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 27px;
  color: #000000;
  width: 120px;
  height: 120px;
  line-height: 120px;
  text-align: center;
}

.avatar-uploader-record {
  position: absolute;
  left: 28%;
  top: 60%;
  transform: translate(-50%, -50%, 0);
  font-size: 13px;
}

.avatar {
  width: 120px;
  height: 120px;
  display: block;
}
</style>
